package com.example.owner.lettery1.base

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import com.example.owner.lettery1.R
import com.example.owner.lettery1.utils.BaseImp


abstract class KBaseActivity<P> : AppCompatActivity(), BaseImp<P> {

    var presenter : P ? = null
    var toolbar : Toolbar? = null
    private var container : FrameLayout? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_base)
        presenter = onCreatePresenter()
        onInitView()
        onLoadData()
        setupListener()
    }


    override fun setupListener() {
        toolbar!!.setNavigationOnClickListener { finish() }
    }

    override fun onInitView() {
        toolbar = findViewById(R.id.toolbar)

        container = findViewById(R.id.container)
        setSupportActionBar(toolbar)
    }

    open fun addContentView(res : Int){
        val view  = LayoutInflater.from(this).inflate(res, null)
        addContentView(view)
    }

    open fun addContentView(view : View){
        container!!.removeAllViews()
        container!!.addView(view)
    }
}